

import java.util.ArrayList;


public class Statements {

	ArrayList<Statement> statements;

	public Statements() {
		statements = new ArrayList<Statement>();
	}

	public void addstatement(Statement s) {
		statements.add(s);
	}

	public void check() throws SemanticException {
		for (Statement s : statements)
			s.check();
	}

	public boolean haveReturnStatement() {
		// unconditional
		for (Statement s : statements)
			if (s.isReturnStatement())
				return true;
		// conditional
		// check all if conditions
		for (Statement s : statements)
			if (s instanceof IfStmt) {
				if (s.hasReturnStatement())
					return true;
			}
		return false;
	}

	public String toString() {
		if (statements.size() == 0)
			return "";
		String ret = "";
		String s = "";
		for (Statement e : statements)
			s += e.toString();
		for (String st : s.split("\n"))
			ret += "| " + st + "\n";
		return ret;
	}
}
